package com.honeywen.mymvc;

import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 967. 连续差相同的数字
 * https://leetcode-cn.com/contest/weekly-contest-117/problems/numbers-with-same-consecutive-differences/
 *
 * @author wangwei
 * @date 2019/8/12
 */
public class NumsSameConsecDiffTest {

    /**
     * 输入：N = 3, K = 7
     * 输出：[181,292,707,818,929]
     * 解释：注意，070 不是一个有效的数字，因为它有前导零
     *
     * @param N
     * @param K
     * @return
     */
    public static int[] numsSameConsecDiff1(int N, int K) {
        if (N == 1) {
            return new int[]{0,1,2,3,4,5,6,7,8,9};
        }
        // start -> end
        double start = Math.pow(10, N - 1);
        double end = Math.pow(10, N) - 1;
        int[] array = new int[1];
        int index = 0;

        int cnt = 0;
        while (cnt + K < 10) {

            if (N % 2 == 0) {
                //
                for (int i = 0; i < N; i++) {
//                    cnt + 10 * K

                }




            } else {
                //

            }


            cnt++;

        }
        return null;


    }
    public static int[] numsSameConsecDiff(int N, int K) {

        if (N == 1) {

            return new int[]{0,1,2,3,4,5,6,7,8,9};
        }

        // start -> end
        double start = Math.pow(10, N - 1);
        double end = Math.pow(10, N) - 1;

        int[] array = new int[1];

        int index = 0;

        for (int i = (int) start; i <= end; i++) {

            if (isSameDiff(i, K)) {

                if (index + 1 > array.length) {
                    array = expend(array);
                }



                array[index++] = i;
            }

        }
        return array;

    }

    private static int[] expend(int[] array) {

        int[] a = new int[array.length  + 1];
        System.arraycopy(array, 0, a, 0, array.length);

        return a;


    }

    private static boolean isSameDiff(int i, int k) {

        int last = i % 10;
        i = i / 10;
        int now = i % 10;
        int diff = now - last > 0 ? now - last: last - now;

        if (diff != k) {
            return false;
        }



        boolean flag = true;
        while (i /10 > 0) {

            last = now;
            i = i / 10;
            now = i % 10;
            int nowdiff = now - last > 0 ? now - last : last - now;

            if (nowdiff != diff) {

                flag = false;
                break;

            }


        }


        return flag;
    }


    public static void main(String[] args) {

        System.out.println(Arrays.toString(numsSameConsecDiff(4, 1)));
//        System.out.println(Arrays.toString(numsSameConsecDiff(3, 1)));
//        System.out.println(Arrays.toString(numsSameConsecDiff(3, 7)));
//        System.out.println(Arrays.toString(numsSameConsecDiff(2, 1)));
//        System.out.println(Arrays.toString(numsSameConsecDiff(3, 1)));
//        System.out.println(Arrays.toString(numsSameConsecDiff(4, 1)));
//        System.out.println(Arrays.toString(numsSameConsecDiff(5, 1)));
//        System.out.println(Arrays.toString(numsSameConsecDiff(6, 1)));




    }

}
